﻿<%@ Page Language="C#" ValidateRequest="false" AutoEventWireup="true"  CodeBehind="index.aspx.cs" Inherits="ZX.WebApp.DesignForm.index" %>

<%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Design Form</title>
  <%--<link href="../Styles/uni-form/uni-form.css" media="screen" rel="stylesheet"/>--%>
   <%-- <link href="../Styles/uni-form/blue.uni-form.css" id="formStyle" title="blue Style" media="screen" rel="stylesheet"/>--%>
    <link href="../Styles/table_style.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.json-2.2.min.js" type="text/javascript"></script>
    <script src="../Scripts/Jquery/jlinq/jlinq.js" type="text/javascript"></script>
    <script src="../Scripts/Jquery/DesignForm/DesignForm.Common.js" type="text/javascript"></script>
   <%-- <script src="../Scripts/Jquery/jquery.processing.plugin.js" type="text/javascript"></script>--%>

</head>

<body>
    <form id="form1" runat="server" >
    <div>
<%--      <div class="header">
        <h2> 步骤：1、选择要生成的表；2、设置排列；3、显示与排序，按勾选的显示，按勾的先后顺序排序：</h2>
      </div>
      <fieldset>
        <div class="ctrlHolder">
          <ul class="alternate">
            <li><label for="">选表： 
            <asp:DropDownList ID="ddltable" runat="server"  AutoPostBack="true" 
            OnSelectedIndexChanged="ddlColNum_OnSelectedIndexChanged">
                </asp:DropDownList>
            </label></li>
           
            <asp:DropDownList ID="ddlColNum" runat="server" Visible="false" >
                    <asp:ListItem Value="1">1</asp:ListItem>
                    <asp:ListItem Value="2">2</asp:ListItem>
                    <asp:ListItem Value="3">3</asp:ListItem>
                    <asp:ListItem Value="4">4</asp:ListItem>
                </asp:DropDownList></label>
          </ul>
         
        </div>
        
        <p />


         <div class="ctrlHolder">
          <label for=""><em>*</em> 字段：</label>
         <asp:CheckBoxList ID="cblcols" RepeatDirection="Horizontal" RepeatLayout="Table" 
                 RepeatColumns="16" OnDataBound="cblcols_OnDataBound" runat="server">
            </asp:CheckBoxList><asp:HiddenField id="hdfseq" runat="server"/>
       
        </div>
 </fieldset>--%>
 <div class="uniForm">
         <CKEditor:CKEditorControl ID="CKEditorDesignForm" runat="server" Height="500" >

        </CKEditor:CKEditorControl>
        
        </div>
      </div>
       
<%--    <script src="../Scripts/Jquery/uni-form/uni-form.jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {

            // init Uni-Form
            $('form.uniForm').uniform();

            // specific for this page
            $(".browse a").click(function (e) {
                e.preventDefault();
                $("#formStyle").attr("href", $(this).attr('rel'));
                return false;
            });
        });
    </script>--%>
    <script src="DesignForm.js" type="text/javascript"></script>
       <script type="text/javascript">
           var _MasterData = [],
               _FormID = '<%= FormID%>',
               _FormName = '<%=FormName %>',
               _MasterTableName = '<%=MasterTableName %>',
               _TemplateName = '<%=TemplateName %>',
               _MasterJson = '',
               _DetailsJson = '<%=DetailsJson %>',
                _DetailsTableName = '',
                oCKeditor = null,
                _SelectArray = null,
                ControlArray = null;



           $(function () {
        
               _SelectArray = new Array();

               DIF.init(_FormID, _FormName, _MasterTableName, _TemplateName);

               DIF.DetailsItems.init(_DetailsJson);
               oCKeditor = CKEDITOR.replace('CKEditorDesignForm',
                  {
                      extraPlugins: 'tableresize',
                      extraPlugins: 'onchange'
                  });

               oCKeditor.on('change', function (e) {
                   //console.log(e) 
                   //alert("1230");
                   var formHtml = oCKeditor.getData();

                   RegularManager(formHtml);

                   //                   var array = stripHTML(formHtml);
                   //                   var array = $.each(formHtml, function (i, n) {
                   //                       if (n == 'select') {
                   //                           alert("Item #" + i + ": " + n);
                   //                       }
                   //                       //第一个参数i表示索引, this表示当前遍历的对象     
                   //                       if (i >= 1) {
                   //                           return false;
                   //                       }
                   //                   });

               });
               oCKeditor.on('instanceReady', function (event) {
                   var editor = event.editor;

                   setTimeout(function () {
                       // Delay bit more if editor is still not ready.
                       if (!editor.element) {
                           setTimeout(arguments.callee, 100);
                           return;
                       }
                       event.removeListener('instanceReady', this.callee);
                       if (editor.name == 'CKEditorDesignForm') {
                           var command = editor.getCommand('maximize');
                           command.exec();
                       }
                   }, 0);
               }, null, null, 9999);

               DIF.GetFormFieldItems.init(_FormID);


               //                  if (typeof (_FieldItemsJson) != 'undefined') {
               //                
               //                  }

               //               oCKeditor.instances['data'].on('blur', function (e) {
               //                   if (e.editor.checkDirty()) {
               //                       alert("1230");
               //                   }
               //               });

               //               $('.CKEditorDesignForm').ckeditor(); 
               //               for (var i in oCKeditor.instances) {
               //                   oCKeditor.instances[i].on('change', function () { alert('text changed!'); }); 
               //               } 

               //               oCKeditor = CKEDITOR.replace('CKEditorDesignForm',
               //				{
               //				    extraPlugins: 'stylesheetparser',
               //				    /*
               //				    * Stylesheet for the contents.
               //				    */
               //				    contentsCss: '../Styles/uni-form/blue.uni-form.css',
               //				    /*
               //				    *  Do not load the default Styles configuration.
               //				    */
               //				    stylesSet: []
               //				});
               //CKEDITOR.replace('CKEditorDesignForm');

               //               _MasterData = DIF.masterFieldData();
               //                var oCKeditor = CKEDITOR.replace('CKEditorDesignForm');
               //               oCKeditor.on('instanceReady', function (event) {
               //                   var editor = event.editor;

               //                   setTimeout(function () {
               //                       // Delay bit more if editor is still not ready.
               //                       if (!editor.element) {
               //                           setTimeout(arguments.callee, 100);
               //                           return;
               //                       }
               //                       event.removeListener('instanceReady', this.callee);
               //                       if (editor.name == 'CKEditorDesignForm') {
               //                           var command = editor.getCommand('maximize');
               //                           command.exec();
               //                       }
               //                   }, 0);
               //               }, null, null, 9999);
           });


              $(document).ready(function () {
          
                  var formHtml = oCKeditor.getData();
                  RegularManager(formHtml);
              });


//           function setTableName() {
//               var tbname = '';
//               tbname = $("#ddltable option:selected").text();
//               if (tbname != '') {
//                   _MasterTableName = tbname;
//                   DIF.MasterData.init();
//               }
//               
//           }



//           function setvalue(obj) {
//               setTableName();
//               var arr = obj.getElementsByTagName("label");
//               var txt = document.getElementById("hdfseq");
//               var inp = obj.getElementsByTagName("input");
//               var num = inp[0].id.split('_');
//               if (inp[0].checked) {
//                   txt.value += arr[0].innerHTML + "#" + num[1] + ";";
//               }
//               else {
//                   txt.value = txt.value.replace(arr[0].innerHTML + "#" + num[1] + ";", "");
//               }
//               getdata(txt.value);
//           }
//           function getdata(txtstr) {
//               var tbname = $("#ddltable option:selected").text(),
//                    cols = $("#ddlColNum option:selected").text(),
//                    seqs = txtstr;
//                DIF.CodeSmithExplorer.init(seqs, tbname, cols);          
//           }
  


        </script> 

    </form>
      
</body>
</html>
